package com.css;

import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;

import java.util.HashMap;

/**
 * <p>
 * -
 * </p>
 *
 * @author css
 * @since 2020/1/11
 */
@Data
@AllArgsConstructor
@NoArgsConstructor
public class Response<T> {
    private String code;
    private T data;
    private String msg;

    public Response(String code, String msg) {
        this.code = code;
        this.msg = msg;
    }

    public static Response success() {
        return new Response<>("200", null, "通过");
    }

    public static <T> Response success(T data) {
        return new Response<T>("200", data, "通过");
    }

    public static <T> Response login() {
        return new Response<T>("401", null, "请重新登录!");
    }

    public Response msg(String msg) {
        this.msg = msg;
        return this;
    }

    public Response put(T data) {
        this.data = data;
        return this;
    }


    public Response data() {
        this.data = (T) new HashMap<String, Object>();
        return this;
    }


    public Response put(String key, T data) {
        ((HashMap) this.data).put(key, data);
        return this;
    }

    public static Response failure() {
        return new Response<>("500", null, "失败");
    }

    public static Response failure(String msg) {
        return new Response<>("500", msg);
    }

}
